<?php
namespace app\system\controller;
use app\system\model\SystemCompany;
use app\admin\common\Base;
class Settings extends Base
{	
	//+--------------------------------------
	//+				系统参数
	//+--------------------------------------
	public function index(){

		$data=db('system_company')->where('enterprise_id',$this->EnterpriseId)->select();
		if (request()->isPost()){
			$data=input('post.');
			//获取post过来数据
			if (isset($data['hidden1'])) {
				$date=[
				'company_name'=>$data['companyName'],
				'company_address'=>$data['companyAddress'],
				'company_tele'=>$data['companyTel'],
				'company_fax'=>$data['companyFax'],
				'company_code'=>$data['postcode'],
				'company_time'=>time(),
				'company_base'=>$data['currency'],
				'company_quantity'=>$data['qtyPlaces'],
				'company_up'=>$data['pricePlaces'],
				'company_stock'=>$data['valMethods'],//1是先进先出算法2是平移平均算法
				'company_inspect'=>$data['requiredCheckStore'],//2是不查仓库1是仓库查看
				'is_del'=>0,
			 ];
			//公司名称验证
				if ($data['companyName']=='') {
					return json(['code'=>1,'msg'=>'公司名称不能为空']);
				}
			
			//更新数据	
			if (db('system_company')->where('enterprise_id',$this->EnterpriseId)->update($date)) {
				return json(['code'=>2,'msg'=>'保存成功']);
			}
				// +--------------------------------------
				// +				功能参数
				// +--------------------------------------
		}elseif(isset($data['hidden2'])){
			$da=[
				 'fun_Dmina'=>$data['cd'],//移动端网页端的值
        		'fun_examine'=>$data['fun_examine'],//启用审核
		        'fun_taxes'=>$data['fun_taxes'],//启用税金
		        'fun_ti'=>$data['fun_ti'],//商品价格是否含税
		        'fun_auxiliary'=>$data['fun_auxiliary'],//启用辅助属性
		        'fun_wisdom'=>$data['fun_wisdom'],//启用智慧微店
		        'fun_sn'=>$data['fun_sn'],//启用序列号
		        'fun_qgp'=>$data['fun_qgp'],//启用批次保质期管理
		        'fun_sa'=>$data['fun_sa'],//启用自动填充结算金额
		        'fun_wa'=>$data['fun_wa'],//启用分仓核算
		        'fun_esup'=>$data['fun_esup'],//启用销售单价为0时提示
		        'fun_aad'=>$data['fun_aad'],//开票金额取优惠后金额
		        'fun_ln'=>$data['fun_ln'],//启用商品编号名称规格型号连续搜索
		        'fun_nc'=>$data['fun_nc'],//启用单据新增客户/供应商取上一次的值
		        'fun_sc'=>$data['fun_sc'],//启用销货类单据新增销售人员默认取上一张单据的值
			    'tax_rate'=>$data['tax_rate'],//税率的值
			];
				$ufun=SystemCompany::where('enterprise_id',$this->EnterpriseId)->update($da);
					if ($ufun) {
						return json(['code'=>1,'msg'=>'更新成功']);
					}else{
						return json(['code'=>2,'msg'=>'更新失败']);
					}
				// +--------------------------------------
				// +				价格取数优先级
				// +--------------------------------------
			}elseif(isset($data['hidden3'])){
				$pap=[
					'pap_ppriec'=>$data['pap_ppriec'],//采购最近价格
			        'pap_pgoos'=>$data['pap_pgoods'],//采购商品价格策略
			        'pap_sgoods'=>$data['pap_sgoods'],//销售最近价格
			        'pap_spriec'=>$data['pap_spriec'],//销售商品价格策略
				];
					$ppap=SystemCompany::where('enterprise_id',$this->EnterpriseId)->update($pap);
						if ($ppap) {
							return json(['code'=>1,'msg'=>'更新成功']);
						}else{
							return json(['code'=>2,'msg'=>'更新失败']);
						}	
			}
			}
		$this->assign('list',$data);
		return $this->fetch('index');
	}
	
}